package com.education.basic.action;

import com.education.basic.entity.Score;
import com.education.basic.service.ScoreService;
import com.yunshangwoniu.core.baseAction.BaseAction;
import com.yunshangwoniu.core.page.Page;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Scope("prototype")
@Namespace("/search")
@ParentPackage(value="struts-default")
public class SearchAction extends BaseAction
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
    private ScoreService scoreService;
    private List<Score> scores;
    private String name;

    @Action(value="department",results={@Result(name="success",location="department.jsp")})
    public String department()
    {
        return "success";
    }
    @Action(value="student",results={@Result(name="success",location="student.jsp")})
    public String student()
    {
        return "success";
    }
    @Action(value="teacher",results={@Result(name="success",location="teacher.jsp")})
    public String teacher()
    {
        return "success";
    }
    @Action(value="fill",results={@Result(name="success",location="fill.jsp")})
    public String fill()
    {
        return "success";
    }
    @Action(value="score",results={@Result(name="success",location="score.jsp")})
    public String score()
    {
        return "success";
    }
    @Action(value="administrator",results={@Result(name="success",location="administrator.jsp")})
    public String administrator()
    {
        return "success";
    }

    @Action(value="search-score",results={@Result(name="success",location="search-score.jsp")})
    public String searchScore()
    {
        Map<String,Object> params = new HashMap<String, Object>();
        params.put("studentName",name);
        Page<Score> page = scoreService.queryScore(params,-1,-1,getRequest());
        scores = page.getRecords();
        return "success";
    }

    public ScoreService getScoreService() {
        return scoreService;
    }

    public void setScoreService(ScoreService scoreService) {
        this.scoreService = scoreService;
    }

    public List<Score> getScores() {
        return scores;
    }

    public void setScores(List<Score> scores) {
        this.scores = scores;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
